/**
 * \file saxer.cc (c) 2011 by Andrew Page 
 *  
 * Provides functionality to build parsers ontop of the libxml2 
 * library that can be easily specified with objects and 
 * pointers to members to handle specific tags 
 *  
 *  
 *  
 */
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <iostream>

#include <string>

#include "ObjectSAXParser.hh"
#include "saxdelegatesT.cc"

using std::string ;
using std::cout ;
using std::endl ;

using objectsaxparser::ObjectSAXParser ;
using objectsaxparser::h ;
using objectsaxparser::attrDict ;

/**
 * Test Class
 * 
 * @author aepage (4/19/2011)
 */
class DOCParser {
public:

    void handleStart(const string& tag) ;
    void handleEnd(const string& tag, const string& data, const attrDict& attrs) ;
};

void DOCParser::handleStart(const string& tag)
{
    cout << "Starting " << tag << endl ;
}

void DOCParser::handleEnd(const string& tag, const string& data, const attrDict& attrs)
{
    cout << "Ending " << tag << endl ;

    for( attrDict::const_iterator it = attrs.begin() ; it != attrs.end() ; it++) {
        cout << "  " << it->first << ":  " << it->second << endl ;
    }

    cout << data << endl ;

}


int main(int arch, char **argv)
{
    ObjectSAXParser parser;
    DOCParser handlers ;

    /*
     * Add a handler to handle the start of the DOC tag
     */
    parser.addStartHandler("DOC", h(&handlers, &DOCParser::handleStart)) ;
    /*
     * Add a handler to handle the closing of a node tag or a 
     * <node/> tag
     */
    parser.addEndHandler("node", h(&handlers, &DOCParser::handleEnd)) ;

    /*
     * parse the file
     */
    parser.parse(argv[1]) ;

}


